<div id="toolbar" >
  <div class="right-toolbar">
  <a title="Thêm máy ảo mới">
  <button onclick="location.href='<?php echo $this->_baseUrl;?>/admin/vm/create'">
  <img src="<?php echo $this->_baseUrl;?>/public/images/web/insert.png" height="32px" width="32px"/>
  <span><p>Thêm mới</p></span>
  </button>
  </a>
  </div>
  <div class="left-toolbar">
  <img src="<?php echo $this->_baseUrl;?>/public/images/web/vmware.png" height="48px" width="48px"/>
  <span>Quản lý máy ảo</span>
  </div>
</div>

<div id="box-content">
 <div id="box-content1">
    <div id="box-content-top">
          
               <div class="filter" style="margin-left: 50px; border-style: none;">
                    <span style="padding-right: 15px; font-weight: bold;">Trạng thái</span>
                    <select id="filter_status" name="filter_status" class="styled"> 
					<option value="2" <?php if($this->input_status == 2) echo "selected='selected'";?>>Tất cả</option> 
					<option value="1" <?php if($this->input_status == 1) echo "selected='selected'";?>>Đang chạy</option> 
					<option value="0" <?php if($this->input_status == 0) echo "selected='selected'";?>>Đang tắt</option> 
				    </select>
               </div>  
               
               <div class="filter" style="margin-left: 50px; border-style: none;">
                    <span style="padding-right: 15px; font-weight: bold;">Tài khoản</span>
                    <select id="filter_user" name="filter_user" class="styled"> 
					<option value="0" <?php if($this->input_userid == 0) echo "selected='selected'";?>>Tất cả</option>
					<?php 
					   if($this->listUser != null)
					   {
					   	 $countUser = count($this->listUser);
					   	 for ($j = 0; $j < $countUser; $j++) {
					 ?>
					     <option value="<?php echo $this->listUser[$j]['user_id'];?>" <?php if($this->input_userid == $this->listUser[$j]['user_id']) echo "selected='selected'";?>><?php echo $this->listUser[$j]['username'];?></option> 
					
					 <?php   	 	
					   	 }
					   }
					?>
				    </select>
               </div> 
              
               <script type="text/javascript">
	               $(document).ready(function(){
			         	 function loadPage(status,userid){

					       if(userid == 0)
					       {      	
				         		 if(status == 0)
				         			location.href='<?php echo $this->_baseUrl;?>/admin/vm/status/stop';
				         		  else
				         			 if(status == 1)
						         			location.href='<?php echo $this->_baseUrl;?>/admin/vm/status/start';
						         			else
								         			location.href='<?php echo $this->_baseUrl;?>/admin/vm';
					       }
					       else
					       	{
					    	   if(status == 0)
				         			location.href='<?php echo $this->_baseUrl;?>/admin/vm/status/stop/u/'+userid;
				         		  else
				         			 if(status == 1)
						         			location.href='<?php echo $this->_baseUrl;?>/admin/vm/status/start/u/'+userid;
						         			else
								         			location.href='<?php echo $this->_baseUrl;?>/admin/vm/u/'+userid;
					       	}     
					      }
			             $('#filter_status').change(function() {
			            	  loadPage($(this).val(),$('#filter_user').val());
			            	});
			             $('#filter_user').change(function() {
			            	  loadPage($('#filter_status').val(),$(this).val());
			            	}); 
			           
			   		 });
	
			    	function clickVm(id,type){
			    		if(type == 0){
			    			$('html, body').animate({ scrollTop: 0 }, 'slow');
			    			$('.loading').show();
			    			location.href='<?php echo $this->_baseUrl;?>/admin/vm/stop/id/'+id;
			    		}
			    		else
			    		{
			    			$('html, body').animate({ scrollTop: 0 }, 'slow');
			    			$('.loading').show();
			    			location.href='<?php echo $this->_baseUrl;?>/admin/vm/start/id/'+id;
			    		}
			    	}

			    	function del(id){
						if(confirm('Bạn có muốn xóa tài khoản này ?')){
							$('html, body').animate({ scrollTop: 0 }, 'slow');
							$('.loading').show();
							location.href='<?php echo $this->_baseUrl;?>/admin/vm/delete/id/'+id;
					    }
			    	}		
						
               </script>
               	 
			 
                 
    </div>
 
    
    <div class = "paging">
   </div> 
   
   <script type="text/javascript">
   $(document).ready(function(){
	  loadPage();
	  setInterval("loadPage()",250);
	});

      var lasturl="p";
  	  function loadContent(page){
   		 $('.paging').load("<?php echo $this->_baseUrl;?>/admin/vm/paging/s/<?php echo $this->status;?>/u/<?php echo $this->userid;?>/p/"+page);
	  }
	  
	  function loadPage(){
		  hash = window.location.hash;
		  if(hash != lasturl)    
		    {
		        lasturl=hash;
		        page = 1;
				if(hash != ""){
				  	  hash = hash.replace('#p','');
				  	  hash = hash.replace('#','');
				  	  page = hash; 
				}
				loadContent(page);
		    }
	  }
   </script>
   
 
 </div>
</div>